package com.fifth.emp.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.Role;
import com.fifth.emp.service.IRoleService;
import com.fifth.emp.vo.RoleVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 徐志豪
 * @since 2022-09-02
 */
@RestController
@RequestMapping("/emp/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    /**
     * 查询所有角色
     */
    @PostMapping("/selectRoleAll")
    public CommonResult selectRoleAll(){
        return roleService.selectRoleAll();
    }

    /**
     *模糊分页查询角色
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("getRole")
    public CommonResult getRole(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize,@RequestBody Role role){
        return roleService.getRole(currentPage,pageSize,role);
    }

    /**
     * 修改角色状态
     * @param
     * @return
     */
    @PostMapping("upStatus/{id}/{status}")
    public CommonResult upStatus(@PathVariable String id,@PathVariable String status){
        return roleService.upStatus(id,status);
    }

    /**
     * 增加角色
     * @return
     */
    //@CrossOrigin
    @PostMapping("addRole")
    public CommonResult addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }


    /**
     * 删除角色
     * @param id
     * @return
     */
    @PostMapping("deleteRole/{id}")
    public CommonResult deleteRole(@PathVariable String id){
        return roleService.deleteRole(id);
    }

    /**
     * 根据role id 查询具有的权限
     */

    //根据角色id查询当前角色具有的权限和所有权限
    @PostMapping("selectPermission/{roleId}")
    public CommonResult selectPermission(@PathVariable String roleId){
        return roleService.selectPermission(roleId);
    }


    /**
     * 修改角色
     * @param role
     * @return
     */
    @PostMapping("/updateRole")
    public CommonResult updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }
}
